<!--
* @Author: bln
* @Date:  2023-11-10 14:12:03
 * @FilePath: \zmglpt-ui-mobile\src\pages\check\approve\auditRecordApproval.vue
* @Description: 市管-检查记录补录--辽宁 统一待办审批跳转页
-->

<template>
	<view class="page">
		<!-- #ifndef H5-DINGDING -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999"></theme-navbar>
		<!-- #endif -->
		<view class="content">
			<u-form ref="uForm" v-model="baseInfo" label-position="top" label-width="auto">
				<form-section title="基础信息"></form-section>
				<u-form-item label="计划日期">
					<u-input placeHolder="" type="text" :disabled="true" v-model="baseInfo.planDate"></u-input>
				</u-form-item>
				<u-form-item label="计划检查户数">
					<u-input placeHolder="" type="text" :disabled="true" v-model="baseInfo.planCheckNum"></u-input>
				</u-form-item>
				<u-form-item label="计划执行人">
					<u-input placeHolder="" type="text" :disabled="true" v-model="baseInfo.planExecutors"></u-input>
				</u-form-item>
				<u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()"
					:height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
				<u-collapse ref="cons" @change="changeHeight()">
					<u-collapse-item>
						<template #title>
							<u-row>
								<u-col span="12" style="display: flex">
									<view class="title"></view>
									<view class="basicHead">临时任务详情</view>
								</u-col>
							</u-row>
						</template>
						<scroll-view :scroll-y="false" :scroll-x="true"
							:style="{ height: scrollRealHeight, marginTop: '5px', paddingBottom:'10px'}">
							<u-table class="tb-lay" ref="tbRef">
								<u-tr>
									<u-th width="4%">序号</u-th>
									<u-th width="8%">任务主体</u-th>
									<u-th width="10%">任务来源</u-th>
									<u-th width="10%">任务来源子来源</u-th>
									<u-th width="5%">受理单号</u-th>
									<u-th width="12%">许可证号</u-th>
									<u-th width="10%">企业名称</u-th>
									<u-th width="8%">负责人</u-th>
									<u-th width="10%">联系电话</u-th>
									<u-th width="18%">经营场所地址</u-th>
									<u-th width="10%">经营状态</u-th>
									<u-th width="5%">所属组织</u-th>
								</u-tr>
								<u-tr v-for="(it, index) in dataSource" :key="'ds' + index">
									<u-td width="4%">{{ index + 1 }}</u-td>
									<u-td width="8%">{{ it.taskSubjectName || '&nbsp;'  }}</u-td>
									<u-td width="10%">{{ it.taskSourceName || '&nbsp;' }}</u-td>
									<u-td width="10%">{{ it.taskSourceItemName || '&nbsp;' }}</u-td>
									<u-td width="5%">{{ it.applyCode || '&nbsp;' }}</u-td>
									<u-td width="12%">{{ it.licNo || '&nbsp;' }}</u-td>
									<u-td width="10%">{{ it.companyName || '&nbsp;' }}</u-td>
									<u-td width="8%">{{ it.managerName || '&nbsp;' }}</u-td>
									<u-td width="10%">{{ it.retailTel || '&nbsp;' }}</u-td>
									<u-td width="18%">{{ it.businessAddr || '&nbsp;' }}</u-td>
									<u-td width="10%">{{ it.licStatusName || '&nbsp;' }}</u-td>
									<u-td width="5%">{{ it.orgName || '&nbsp;' }}</u-td>
								</u-tr>
							</u-table>
						</scroll-view>
					</u-collapse-item>
				</u-collapse>
				<!-- 审批意见 -->
				<view v-if="ifSub">
					<u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()"
					:height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
					<form-section title="审批意见"></form-section>
					<u-form-item label="">
						<u-radio-group v-model="approvalParams.approveResult" @change="handleChangeRadio()" :disabled="approvalIsEdit">
							<u-radio v-for="(item,index) in approvalParamsList" :key="index" :label="item.label" :name="item.value">{{ item.label }}</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="">
						<u-input placeHolder="" type="textarea" v-model="approvalParams.approveMemo" :disabled="approvalIsEdit"></u-input>
					</u-form-item>
					<u-form-item label="签名">
						<u-input placeHolder="" type="text" :disabled="true" v-model="approvalParams.approvePersonName"></u-input>
					</u-form-item>
					<u-form-item label="提交时间">
						<u-input placeHolder="" type="text" :disabled="true" v-model="approvalParams.approveTime"></u-input>
					</u-form-item>
				</view>
				<!-- 审批历史开始 -->
				<u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()"
					:height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
				<form-section title="审批历史"></form-section>
				<u-form-item label="" class="u-m-l-12">
					<flow-his-no-doc :bizUuid="prvParam.bizUuid" :processDefKey="prvParam.gfCode"
						:endTitle="endTitle"></flow-his-no-doc>
				</u-form-item>
				<!-- 审批历史结束 -->
			</u-form>
		</view>
		<view class="submit-btns btn-other-cls" v-if="ifSub" >
			<u-button class="u-btn" type="primary" @click="submit">审批</u-button>
		</view>
	</view>
</template>

<script>
	import DicChoice from '@/components/dic_choice.vue';
	import formSection from '@/components/form-section.vue';
	import FlowHisNoDoc from '@/components/flow-his-no-doc.vue';
	import creditService from '@/service/check/check.service.js'
	import { M_DAY_PLAN_STATUS } from '@/service/check/mapping/enum.js'
	
	export default {
		components: {
			formSection,
			FlowHisNoDoc,
			DicChoice
		},
		data() {
			return {
				step: '',
				ifSub: false,
				endTitle: '',
				prvParam: {}, // 路由参数
				baseInfo: {}, // 详情
				dataSource: [], // 临时任务详情
				scrollRealHeight: '50px',
				approvalIsEdit: true,
				approvalParamsList: [{
					label: '同意',
					value: '01'
				}, {
					label: '不同意',
					value: '02'
				}],
				approvalParams: {
					approveResult: '01',
					approveMemo: '同意',
					approvePersonName: ' ',
					approveTime: ''
				}
			}
		},
		onLoad () {
			this.prvParam = this.getRouteParam() || {}
			this.getBasicInfo()
		},
		methods: {
			getDicNameByKeyCode(key, code) {
				return this.$u.dic.getDicNameByKeyCode(key, code);
			},
			updateTableHeight() {
				setTimeout(() => {
					this.scrollRealHeight = this.$refs.tbRef.$el.clientHeight + 5 + 'px';
				}, 100);
			},
			changeHeight() {
				this.$nextTick(() => {
					this.$refs.cons.init()
				})
			},
			getGapMarginRowNumber() {
				return '-' + this.$theme.cm_content_paddng_row.replace('rpx', '')
			},
			// 审批意见更新
			handleChangeRadio() {
				this.approvalParams.approveMemo = this.approvalParams.approveResult === '01' ? '同意' : '不同意'
			},
			// 获取信息详情
			async getBasicInfo () {
				try {
					this.$modal.showLoading('加载中...')
					const { bean, success, msg } = await creditService.findCheckTempFormList({ bizUuid:this.prvParam.bizUuid })
					if (success) {
						this.baseInfo.planDate = bean.planDate;
						this.baseInfo.planCheckNum = bean.planCheckNum;
						this.baseInfo.planExecutors = bean.planExecutors;
						this.approvalParams.approveTime = bean.createTime
						this.approvalParams.approvePersonName = bean.creatorName
						this.dataSource = bean.checkTempList || []
						this.endTitle = this.baseInfo.approveStatus == M_DAY_PLAN_STATUS.TERMINATION ? '结束' : '...'
						this.getCurrStatus();
						this.updateTableHeight();
					} else {
						this.$modal.alert(msg, () => this.error())
					}
					this.$modal.hideLoading()
				} catch (e) {
					this.$modal.hideLoading()
					this.$modal.alert('加载失败' + e, () => this.error())
				}
			},
			async submit() {
				try {
					this.$modal.showLoading('请稍后...')
					const memo = this.approvalParamsList.find(item => item.value === this.approvalParams.approveResult)?.label || ''
					const params = {
						nextPersonUuids: '',
						processDefKey: this.prvParam.gfCode,
						bizUuid: this.prvParam.bizUuid,
						approveMemo: `【${memo}】${this.approvalParams.approveMemo}`,
						approveResult: this.approvalParams.approveResult, // 01 同意 02 不同意
						approvePersonUuid: this.$store.state.userInfo.user.personUuid
					}
					const { success, msg } = await creditService.addTempClientAudit(params)
					if (success) {
						this.backPrev({ paramKey: 'refresh', param: true })
					} else {
						this.$u.toast(msg)
					}
					this.$modal.hideLoading()
				} catch (e) {
					this.$modal.hideLoading()
					this.$u.toast('提交失败' + e)
				}
			},
			getCurrStatus() {
				creditService.getFlowNodeStep({
					bizUuid: this.prvParam.bizUuid,
					processDefKey: this.prvParam.gfCode
				}).then((res) => {
					if (res.success) {
						this.step = res.bean.step;
						if (this.step == 'view') {
							this.ifSub = false;
						} else {
							this.ifSub = true
						}
					}
				});
				creditService.getApproves({
					bizUuid: this.prvParam.bizUuid,
					processDefKey: this.prvParam.gfCode
				}).then((res) => {
					let approvalParams = res['bean']['end'];
					this.approvalParams.approveResult = approvalParams.approveResult || '01';
					this.approvalParams.approveMemo = approvalParams.approveMemo || '同意';
					this.approvalParams.approvePersonName = approvalParams.approvePersonName || '';
					this.approvalParams.approveTime = approvalParams.approveTime || '';
					this.approvalIsEdit = !approvalParams.isCurryApproveNode;
				});
			}
		},
		error() {
			uni.navigateBack()
		}
	}
</script>

<style scoped lang="scss">
	.page {
		padding: 0;
	}
	.title {
		width: 8rpx;
		height: 32rpx;
		background: #0079f2;
		opacity: 1;
		margin-left: -5px;
		border-radius: 4rpx;
		float: left;
		margin-right: 16rpx;
	}
	.basicHead {
		height: 36rpx;
		line-height: 36rpx;
		text-align: center;
		float: left;
		font-weight: bold;
		font-size: 16px;
	}
	.sub-title {
		background: #f5f5f5;
		color: #989ea1;
		font-size: 24rpx;
		border-radius: 4px;
		margin-right: 10px;
		padding: 4px 8px;
	}
	.f-ctn {
		width: 100%;
	}
	.tb-lay {
		width: 900px;
		margin-left: 1px;
		margin-right: 1px;
	}
	.content {
		padding-left: $cm-content-paddng-row;
		padding-right: $cm-content-paddng-row;
		padding-top: $cm-conent-padding-column;
		padding-bottom: 70px;
	}
	.td-text {
		word-break: break-all;
		word-wrap: break-word;
	}
	/deep/.u-td {
		height: auto;
	}
</style>